import * as Matter from 'matter-js';
import * as PIXI from "pixi.js";
import { App } from '../system/App';
// [10]

// [/10]

export class BasketBoard {
  constructor(x, y) {
    this.width = App.config.basket.board.width;
    this.height = App.config.basket.board.height;

    this.dx = 5;
    this.createSprite(x, y);

    this.options = {
      isStatic: true,
      render: {
        visible: true,
        fillStyle: 'yellow',
      }
    }
  }


  createBody() {
    this.body = Matter.Bodies.rectangle(
      this.width / 2 + this.sprite.parent.x,
      this.height / 2 + this.sprite.parent.y,
      this.width,
      this.height,
      this.options
    );

    Matter.World.add(App.physics.world, this.body);
  }

  createSprite(x, y) {
    this.sprite = App.sprite(`basket_board`);
    this.sprite.x = 0;
    this.sprite.y = 0;
    this.sprite.width = this.width;
    this.sprite.height = this.height;
  }

  move(dx, y) {
    if (dx > 0) {
      if (this.body && this.body.position.x < App.config.basket.board.width - this.sprite.width / 2) {
        Matter.Body.setPosition(
          this.body, {
            x: this.body.position.x + dx,
            y: y - this.height / 2 || this.body.position.y
          });
      }
    } else {
      if (this.body && this.body.position.x > (0 - App.config.basket.board.width - this.sprite.width / 2)) {
        Matter.Body.setPosition(this.body, {
          x: this.body.position.x + dx,
          y: y - this.height / 2 || this.body.position.y
        });
      }
    }

  }

  // 06


}